layui.use(['table','form','laydate','laytpl','element'], function() {
	var table = layui.table;
	var form = layui.form,
    $ = layui.jquery,
    laydate = layui.laydate,
    laytpl = layui.laytpl,
    element = layui.element;

	/*加载学校类型下拉框*/
	$.ajax({
		type : 'get',
		url : '../json/schoolType.json',
		datatype : 'json',
		success : function(schooltypedate) {
			if (schooltypedate.code == 0) {
				var str = "";
				for(var i = 0; i < schooltypedate.count; i++){
					str += '<option value=' + schooltypedate.data[i].id + '>'+ schooltypedate.data[i].name+'</option>';
				}
				$("#selschooltype").append(str);
				form.render("select");
			}
		}
	});
	
	/*点击学校类型下拉框*/
	form.on('select(selschooltype)', function(data) {
		var schooltype = data.value;
		if(schooltype=="00" || schooltype==null || schooltype=='null'){
			schooltype="";
		}
		$("#selschool").html("");
		//根据阶段筛选学校
		$.ajax({
			type : 'get',
			url : '../sysschoolmanagement/getschoolbywhere?schooltype='+schooltype,
			datatype : 'json',
			success : function(schooldata) {
				if (schooldata.code == 0) {
					var str = "<option value='00'>请选择学校</option>";
					for(var i = 0; i < schooldata.count; i++){
						str += '<option value=' + schooldata.data[i].schoolid + '>'+ schooldata.data[i].schoolName +'</option>';
					}
					$("#selschool").append(str);
					form.render("select");
				}
				else{
					layer.msg('暂无对应的学校', {icon: 2});
					$("#selschool").html("");
					form.render("select");
				}
				
			}
		});
	});
	
	/*点击测试报告类型筛选表格*/
	table.render({
		elem: '#tabschooleva',
		url: '../sysanecdotestatis/getschoollist',
		title: '学校信息表',
		height: "full-120",
		skin: 'line',
		even: true,
		cols: [
			[{
				type: 'numbers',
				title: '序号',
				align: 'center',
				width: '15%'
			},{
				field: 'schoolName',
				title: '学校名称',
				align: 'center',
				width: '35%'
			}, {
				field: 'schoolType',
				title: '学校类型',
				templet : '#schoolTypeText',
				align: 'center',
				width: '25%'
			}, {
				title: '操作',
				toolbar: '#barDemo',
				align: 'center',
				width: '25%'
			}]
		],page: {
			layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
			groups: 5,
			limit: 10,
			limits: [10, 20, 30, 40, 50],
			theme: '#1E9FFF',						
		}
	});
	
	/*点击查询对学校信息进行筛选*/
	$("#btnselAnecdoteAnalysi").click(function(){
		var schoolid=$("#selschool").val();
		if(schoolid==00 || schoolid==null || schoolid=='null'){
			schoolid="";
		}
		table.render({
			elem: '#tabschooleva',
			url: '../sysanecdotestatis/getschoollist?schoolid='+schoolid,
			title: '学校信息表',
			height: "full-120",
			skin: 'line',
			even: true,
			cols: [
				[{
					type: 'numbers',
					title: '序号',
					align: 'center',
					width: '15%'
				},{
					field: 'schoolName',
					title: '学校名称',
					align: 'center',
					width: '35%'
				}, {
					field: 'schoolType',
					title: '学校类型',
					align: 'center',
					templet : '#schoolTypeText',
					width: '25%'
				}, {
					title: '操作',
					toolbar: '#barDemo',
					align: 'center',
					width: '25%'
				}]
			],page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF',						
			}
		});
	});
	
    //监听行工具事件
    table.on('tool(tabschooleva)', function(obj){
    	var schooldata = obj.data;
	    if(obj.event === 'analysis'){
	    	var para = "schoolid=" + schooldata.schoolid;
			
	    	var index = layer.open({
				type: 2, 
			    title: '学校轶事分布统计结果统计结果',
		        area: ['830px', '95%'],
		        shade: 0.8,
		        maxmin: true,
		        content: ['../anecdotalManagement/schoolAnecdoteStatis.jsp?' + para, 'yes'],
		        cancel: function(){ 
				}
		    });
	    	layer.full(index);
	    	
	    }
	    else if(obj.event === 'printing'){
	    	var para = "schoolid=" + schooldata.schoolid;
			
			var index = layer.open({
				type: 2, 
			    title: '学校轶事分布统计结果统计结果',
		        area: ['830px', '95%'],
		        shade: 0.8,
		        maxmin: true,
		        content: ['../anecdotalManagement/schoolAnecdotePrinter.jsp?' + para, 'yes'],
		        cancel: function(){ 
				}
		    });
	    	layer.full(index);
			
	    }
    });
});